﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace QLDBNH_CLIENT
{
    class chuoi
    {
        //g khong co khoang trang o dau va cuoi chuoi
        //'giua hai tu' hoac 'giua hai ky tu' chi co chua khoang trang.
        //ket qua tra ve la mot 'chuoi'.
        public string c_h_string(string s_input)
        {

            //khai bao bien.
            string s_output = "";
            int i, len, j;

            //gan gia tri.
            len = s_input.Length;
            j = 0;

            //Chuyen chuoi sang mang ky tu.
            char[] mang = new char[10000];
            for (int x = 0; x < len; x++)
            {
                mang[x] = s_input[x];
            }

            //chuan hoa chuoi.
            try
            {
                while ((int)mang[0] == 32)
                {
                    for (i = 1; i < len; i++)
                        mang[i - 1] = mang[i];
                    len = len - 1;
                }
            }
            catch(Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }

            try
            {
                if (len > 0)
                {
                    while ((int)mang[len - 1] == 32)
                    {
                        mang[len - 1] = '\0';
                        len = len - 1;
                        //if (len < 1)
                        //    break;
                    }
                }
            }
            catch(Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }

            try
            {
                i = 0;
                while (i < len)
                {
                    while ((int)mang[i] == 32 && (int)mang[i + 1] == 32)
                    {
                        for (j = i + 1; j < len; j++)
                            mang[j - 1] = mang[j];
                        len = len - 1;
                    }
                    i = i + 1;
                }
            }
            catch(Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }

            //Chuyen mang ky tu thanh chuoi. 
            for (int y = 0; y < len; y++)
                s_output = s_output + mang[y];

            return s_output;
        }

        //r chuoi khong chua khoang trang.
        //ket qua la mot chuoi khong chua 'khoang trang'.
        public string d_k_t(string s_input)
        {
            string s_output = "";
            int i, len, j = 0;

            len = s_input.Length;

            //Chuyen chuoi sang mang ky tu.
            char[] mang = new char[10000];
            for (int x = 0; x < len; x++)
            {
                mang[x] = s_input[x];
            }

            //don ky tu trong chuoi.
            try
            {
                while ((int)mang[0] == 32)
                {
                    for (i = 1; i < len; i++)
                        mang[i - 1] = mang[i];
                    len = len - 1;
                }
            }
            catch(Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }

            try
            {
                if (len > 0)
                {
                    while ((int)mang[len - 1] == 32)
                    {
                        mang[len - 1] = '\0';
                        len = len - 1;
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }

            try
            {
                i = 0;
                while (i < len)
                {
                    while ((int)mang[i] == 32)
                    {
                        for (j = i + 1; j < len; j++)
                            mang[j - 1] = mang[j];
                        len = len - 1;
                    }
                    i = i + 1;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }

            //Chuyen mang ky tu thanh chuoi. 
            for (int y = 0; y < len; y++)
                s_output = s_output + mang[y];

            return s_output;
        }

        //g xoa dau.
        public string xoa_dau(string string_input)
        {
            int i;
            char[] buf;
            string string_output = "";

            buf = string_input.ToCharArray();

            for (i = 0; i < string_input.Length; i++)
                if (buf[i] == 'á')
                    buf[i] = 'a';
                else if (buf[i] == 'à')
                    buf[i] = 'a';
                else if (buf[i] == 'ả')
                    buf[i] = 'a';
                else if (buf[i] == 'ã')
                    buf[i] = 'a';
                else if (buf[i] == 'ấ')
                    buf[i] = 'â';
                else if (buf[i] == 'ầ')
                    buf[i] = 'â';
                else if (buf[i] == 'ẩ')
                    buf[i] = 'â';
                else if (buf[i] == 'ẫ')
                    buf[i] = 'â';
                else if (buf[i] == 'ắ')
                    buf[i] = 'ă';
                else if (buf[i] == 'ằ')
                    buf[i] = 'ă';
                else if (buf[i] == 'ẳ')
                    buf[i] = 'ă';
                else if (buf[i] == 'ẵ')
                    buf[i] = 'ă';
                else if (buf[i] == 'ó')
                    buf[i] = 'o';
                else if (buf[i] == 'ò')
                    buf[i] = 'o';
                else if (buf[i] == 'ỏ')
                    buf[i] = 'o';
                else if (buf[i] == 'õ')
                    buf[i] = 'o';
                else if (buf[i] == 'ố')
                    buf[i] = 'ô';
                else if (buf[i] == 'ồ')
                    buf[i] = 'ô';
                else if (buf[i] == 'ổ')
                    buf[i] = 'ô';
                else if (buf[i] == 'ỗ')
                    buf[i] = 'ô';
                else if (buf[i] == 'ớ')
                    buf[i] = 'ơ';
                else if (buf[i] == 'ờ')
                    buf[i] = 'ơ';
                else if (buf[i] == 'ở')
                    buf[i] = 'ơ';
                else if (buf[i] == 'ỡ')
                    buf[i] = 'ơ';
                else if (buf[i] == 'í')
                    buf[i] = 'i';
                else if (buf[i] == 'ì')
                    buf[i] = 'i';
                else if (buf[i] == 'ỉ')
                    buf[i] = 'i';
                else if (buf[i] == 'ĩ')
                    buf[i] = 'i';
                else if (buf[i] == 'ý')
                    buf[i] = 'y';
                else if (buf[i] == 'ỳ')
                    buf[i] = 'y';
                else if (buf[i] == 'ỷ')
                    buf[i] = 'y';
                else if (buf[i] == 'ỹ')
                    buf[i] = 'y';
                else if (buf[i] == 'é')
                    buf[i] = 'e';
                else if (buf[i] == 'è')
                    buf[i] = 'e';
                else if (buf[i] == 'ẻ')
                    buf[i] = 'e';
                else if (buf[i] == 'ẽ')
                    buf[i] = 'e';
                else if (buf[i] == 'ế')
                    buf[i] = 'ê';
                else if (buf[i] == 'ề')
                    buf[i] = 'ê';
                else if (buf[i] == 'ể')
                    buf[i] = 'ê';
                else if (buf[i] == 'ễ')
                    buf[i] = 'ê';
                else if (buf[i] == 'À')
                    buf[i] = 'A';
                else if (buf[i] == 'Á')
                    buf[i] = 'A';
                else if (buf[i] == 'Ả')
                    buf[i] = 'A';
                else if (buf[i] == 'Ã')
                    buf[i] = 'A';
                else if (buf[i] == 'Ấ')
                    buf[i] = 'Â';
                else if (buf[i] == 'Ầ')
                    buf[i] = 'Â';
                else if (buf[i] == 'Ẩ')
                    buf[i] = 'Â';
                else if (buf[i] == 'Ẫ')
                    buf[i] = 'Â';
                else if (buf[i] == 'Ắ')
                    buf[i] = 'Ă';
                else if (buf[i] == 'Ằ')
                    buf[i] = 'Ă';
                else if (buf[i] == 'Ẳ')
                    buf[i] = 'Ă';
                else if (buf[i] == 'Ẵ')
                    buf[i] = 'Ă';
                else if (buf[i] == 'Ó')
                    buf[i] = 'O';
                else if (buf[i] == 'Ò')
                    buf[i] = 'O';
                else if (buf[i] == 'Ỏ')
                    buf[i] = 'O';
                else if (buf[i] == 'Õ')
                    buf[i] = 'O';
                else if (buf[i] == 'Ố')
                    buf[i] = 'Ô';
                else if (buf[i] == 'Ồ')
                    buf[i] = 'Ô';
                else if (buf[i] == 'Ổ')
                    buf[i] = 'Ô';
                else if (buf[i] == 'Ỗ')
                    buf[i] = 'Ô';
                else if (buf[i] == 'Ớ')
                    buf[i] = 'Ơ';
                else if (buf[i] == 'Ờ')
                    buf[i] = 'Ơ';
                else if (buf[i] == 'Ở')
                    buf[i] = 'Ơ';
                else if (buf[i] == 'Ỡ')
                    buf[i] = 'Ơ';
                else if (buf[i] == 'Í')
                    buf[i] = 'I';
                else if (buf[i] == 'Ì')
                    buf[i] = 'I';
                else if (buf[i] == 'Ỉ')
                    buf[i] = 'I';
                else if (buf[i] == 'Ĩ')
                    buf[i] = 'I';
                else if (buf[i] == 'Ý')
                    buf[i] = 'Y';
                else if (buf[i] == 'Ỳ')
                    buf[i] = 'Y';
                else if (buf[i] == 'Ỷ')
                    buf[i] = 'Y';
                else if (buf[i] == 'Ỹ')
                    buf[i] = 'Y';
                else if (buf[i] == 'É')
                    buf[i] = 'E';
                else if (buf[i] == 'È')
                    buf[i] = 'E';
                else if (buf[i] == 'Ẻ')
                    buf[i] = 'E';
                else if (buf[i] == 'Ẽ')
                    buf[i] = 'E';
                else if (buf[i] == 'Ế')
                    buf[i] = 'Ê';
                else if (buf[i] == 'Ề')
                    buf[i] = 'Ê';
                else if (buf[i] == 'Ể')
                    buf[i] = 'Ê';
                else if (buf[i] == 'Ễ')
                    buf[i] = 'Ê';
                else if (buf[i] == 'Ễ')
                    buf[i] = 'Ê';
                else { }

            for (i = 0; i < string_input.Length; i++)
                string_output = string_output + buf[i];

            return string_output;
        }

        //g xoa dau.
        public string xoa_dau1(string string_input)
        {
            int i;
            char[] buf;
            string string_output = "";

            buf = string_input.ToCharArray();
            for (i = 0; i < string_input.Length; i++)
                if (buf[i] == 'á')
                    buf[i] = 'a';
                else if (buf[i] == 'à')
                    buf[i] = 'a';
                else if (buf[i] == 'ả')
                    buf[i] = 'a';
                else if (buf[i] == 'ã')
                    buf[i] = 'a';
                else if (buf[i] == 'ấ')
                    buf[i] = 'a';
                else if (buf[i] == 'ầ')
                    buf[i] = 'a';
                else if (buf[i] == 'ẩ')
                    buf[i] = 'a';
                else if (buf[i] == 'ẫ')
                    buf[i] = 'a';
                else if (buf[i] == 'ắ')
                    buf[i] = 'a';
                else if (buf[i] == 'ằ')
                    buf[i] = 'a';
                else if (buf[i] == 'ẳ')
                    buf[i] = 'a';
                else if (buf[i] == 'ẵ')
                    buf[i] = 'a';
                else if (buf[i] == 'ó')
                    buf[i] = 'o';
                else if (buf[i] == 'ò')
                    buf[i] = 'o';
                else if (buf[i] == 'ỏ')
                    buf[i] = 'o';
                else if (buf[i] == 'õ')
                    buf[i] = 'o';
                else if (buf[i] == 'ố')
                    buf[i] = 'o';
                else if (buf[i] == 'ồ')
                    buf[i] = 'o';
                else if (buf[i] == 'ổ')
                    buf[i] = 'o';
                else if (buf[i] == 'ỗ')
                    buf[i] = 'o';
                else if (buf[i] == 'ớ')
                    buf[i] = 'o';
                else if (buf[i] == 'ờ')
                    buf[i] = 'o';
                else if (buf[i] == 'ở')
                    buf[i] = 'o';
                else if (buf[i] == 'ỡ')
                    buf[i] = 'o';
                else if (buf[i] == 'í')
                    buf[i] = 'i';
                else if (buf[i] == 'ì')
                    buf[i] = 'i';
                else if (buf[i] == 'ỉ')
                    buf[i] = 'i';
                else if (buf[i] == 'ĩ')
                    buf[i] = 'i';
                else if (buf[i] == 'ý')
                    buf[i] = 'y';
                else if (buf[i] == 'ỳ')
                    buf[i] = 'y';
                else if (buf[i] == 'ỷ')
                    buf[i] = 'y';
                else if (buf[i] == 'ỹ')
                    buf[i] = 'y';
                else if (buf[i] == 'é')
                    buf[i] = 'e';
                else if (buf[i] == 'è')
                    buf[i] = 'e';
                else if (buf[i] == 'ẻ')
                    buf[i] = 'e';
                else if (buf[i] == 'ẽ')
                    buf[i] = 'e';
                else if (buf[i] == 'ế')
                    buf[i] = 'e';
                else if (buf[i] == 'ề')
                    buf[i] = 'e';
                else if (buf[i] == 'ể')
                    buf[i] = 'e';
                else if (buf[i] == 'ễ')
                    buf[i] = 'e';
                else if (buf[i] == 'À')
                    buf[i] = 'A';
                else if (buf[i] == 'Á')
                    buf[i] = 'A';
                else if (buf[i] == 'Ả')
                    buf[i] = 'A';
                else if (buf[i] == 'Ã')
                    buf[i] = 'A';
                else if (buf[i] == 'Ấ')
                    buf[i] = 'A';
                else if (buf[i] == 'Ầ')
                    buf[i] = 'A';
                else if (buf[i] == 'Ẩ')
                    buf[i] = 'A';
                else if (buf[i] == 'Ẫ')
                    buf[i] = 'A';
                else if (buf[i] == 'Ắ')
                    buf[i] = 'A';
                else if (buf[i] == 'Ằ')
                    buf[i] = 'A';
                else if (buf[i] == 'Ẳ')
                    buf[i] = 'A';
                else if (buf[i] == 'Ẵ')
                    buf[i] = 'A';
                else if (buf[i] == 'Ó')
                    buf[i] = 'O';
                else if (buf[i] == 'Ò')
                    buf[i] = 'O';
                else if (buf[i] == 'Ỏ')
                    buf[i] = 'O';
                else if (buf[i] == 'Õ')
                    buf[i] = 'O';
                else if (buf[i] == 'Ố')
                    buf[i] = 'O';
                else if (buf[i] == 'Ồ')
                    buf[i] = 'O';
                else if (buf[i] == 'Ổ')
                    buf[i] = 'O';
                else if (buf[i] == 'Ỗ')
                    buf[i] = 'O';
                else if (buf[i] == 'Ớ')
                    buf[i] = 'O';
                else if (buf[i] == 'Ờ')
                    buf[i] = 'O';
                else if (buf[i] == 'Ở')
                    buf[i] = 'O';
                else if (buf[i] == 'Ỡ')
                    buf[i] = 'O';
                else if (buf[i] == 'Í')
                    buf[i] = 'I';
                else if (buf[i] == 'Ì')
                    buf[i] = 'I';
                else if (buf[i] == 'Ỉ')
                    buf[i] = 'I';
                else if (buf[i] == 'Ĩ')
                    buf[i] = 'I';
                else if (buf[i] == 'Ý')
                    buf[i] = 'Y';
                else if (buf[i] == 'Ỳ')
                    buf[i] = 'Y';
                else if (buf[i] == 'Ỷ')
                    buf[i] = 'Y';
                else if (buf[i] == 'Ỹ')
                    buf[i] = 'Y';
                else if (buf[i] == 'É')
                    buf[i] = 'E';
                else if (buf[i] == 'È')
                    buf[i] = 'E';
                else if (buf[i] == 'Ẻ')
                    buf[i] = 'E';
                else if (buf[i] == 'Ẽ')
                    buf[i] = 'E';
                else if (buf[i] == 'Ế')
                    buf[i] = 'E';
                else if (buf[i] == 'Ề')
                    buf[i] = 'E';
                else if (buf[i] == 'Ể')
                    buf[i] = 'E';
                else if (buf[i] == 'Ễ')
                    buf[i] = 'E';
                else if (buf[i] == 'đ')
                    buf[i] = 'd';
                else if (buf[i] == 'Đ')
                    buf[i] = 'D';
                else { }

            for (i = 0; i < string_input.Length; i++)
                string_output = string_output + buf[i];

            return string_output;
        }

        //g chi chua 26 chu cai.
        //=0 hop le, != khong hop le.
        public int _26_kt(string string_input)
        {
            int i, dem = 0, t = 1;
            string buf="";

            for (i = 0; i < string_input.Length; i++)
            {
                buf = buf + string_input[i];
                if (
                    buf.CompareTo("á") == 0 ||
                    buf.CompareTo("à") == 0 ||
                    buf.CompareTo("ả") == 0 ||
                    buf.CompareTo("ã") == 0 ||
                    buf.CompareTo("ấ") == 0 ||
                    buf.CompareTo("ấ") == 0 ||
                    buf.CompareTo("ấ") == 0 ||
                    buf.CompareTo("ầ") == 0 ||
                    buf.CompareTo("ẩ") == 0 ||
                    buf.CompareTo("ẫ") == 0 ||
                    buf.CompareTo("ắ") == 0 ||
                    buf.CompareTo("ằ") == 0 ||
                    buf.CompareTo("ẳ") == 0 ||
                    buf.CompareTo("ẵ") == 0 ||
                    buf.CompareTo("â") == 0 ||
                    buf.CompareTo("ă") == 0 ||
                    buf.CompareTo("a") == 0 ||
                    buf.CompareTo("ó") == 0 ||
                    buf.CompareTo("ò") == 0 ||
                    buf.CompareTo("ỏ") == 0 ||
                    buf.CompareTo("õ") == 0 ||
                    buf.CompareTo("ố") == 0 ||
                    buf.CompareTo("ồ") == 0 ||
                    buf.CompareTo("ổ") == 0 ||
                    buf.CompareTo("ỗ") == 0 ||
                    buf.CompareTo("ớ") == 0 ||
                    buf.CompareTo("ờ") == 0 ||
                    buf.CompareTo("ở") == 0 ||
                    buf.CompareTo("ỡ") == 0 ||
                    buf.CompareTo("o") == 0 ||
                    buf.CompareTo("ơ") == 0 ||
                    buf.CompareTo("ô") == 0 ||
                    buf.CompareTo("í") == 0 ||
                    buf.CompareTo("ì") == 0 ||
                    buf.CompareTo("ỉ") == 0 ||
                    buf.CompareTo("ĩ") == 0 ||
                    buf.CompareTo("ĩ") == 0 ||
                    buf.CompareTo("ĩ") == 0 ||
                    buf.CompareTo("ĩ") == 0 ||
                    buf.CompareTo("ĩ") == 0 ||
                    buf.CompareTo("i") == 0 ||
                    buf.CompareTo("ý") == 0 ||
                    buf.CompareTo("ỳ") == 0 ||
                    buf.CompareTo("ỷ") == 0 ||
                    buf.CompareTo("ỹ") == 0 ||
                    buf.CompareTo("y") == 0 ||
                    buf.CompareTo("é") == 0 ||
                    buf.CompareTo("è") == 0 ||
                    buf.CompareTo("ẻ") == 0 ||
                    buf.CompareTo("ẽ") == 0 ||
                    buf.CompareTo("ế") == 0 ||
                    buf.CompareTo("ề") == 0 ||
                    buf.CompareTo("ể") == 0 ||
                    buf.CompareTo("ễ") == 0 ||
                    buf.CompareTo("e") == 0 ||
                    buf.CompareTo("ê") == 0 ||
                    buf.CompareTo("À") == 0 ||
                    buf.CompareTo("Á") == 0 ||
                    buf.CompareTo("Ả") == 0 ||
                    buf.CompareTo("Ã") == 0 ||
                    buf.CompareTo("Ấ") == 0 ||
                    buf.CompareTo("Ầ") == 0 ||
                    buf.CompareTo("Ẩ") == 0 ||
                    buf.CompareTo("Ẫ") == 0 ||
                    buf.CompareTo("Ắ") == 0 ||
                    buf.CompareTo("Ằ") == 0 ||
                    buf.CompareTo("Ẳ") == 0 ||
                    buf.CompareTo("Ẵ") == 0 ||
                    buf.CompareTo("A") == 0 ||
                    buf.CompareTo("Â") == 0 ||
                    buf.CompareTo("Ă") == 0 ||
                    buf.CompareTo("Ó") == 0 ||
                    buf.CompareTo("Ò") == 0 ||
                    buf.CompareTo("Ỏ") == 0 ||
                    buf.CompareTo("Ỏ") == 0 ||
                    buf.CompareTo("Ỏ") == 0 ||
                    buf.CompareTo("Õ") == 0 ||
                    buf.CompareTo("Ớ") == 0 ||
                    buf.CompareTo("Ờ") == 0 ||
                    buf.CompareTo("Ở") == 0 ||
                    buf.CompareTo("Ỡ") == 0 ||
                    buf.CompareTo("Ố") == 0 ||
                    buf.CompareTo("Ồ") == 0 ||
                    buf.CompareTo("Ỗ") == 0 ||
                    buf.CompareTo("Ổ") == 0 ||
                    buf.CompareTo("Ô") == 0 ||
                    buf.CompareTo("Ơ") == 0 ||
                    buf.CompareTo("Í") == 0 ||
                    buf.CompareTo("Ì") == 0 ||
                    buf.CompareTo("Ỉ") == 0 ||
                    buf.CompareTo("Ĩ") == 0 ||
                    buf.CompareTo("I") == 0 ||
                    buf.CompareTo("Ý") == 0 ||
                    buf.CompareTo("Ỳ") == 0 ||
                    buf.CompareTo("Ỷ") == 0 ||
                    buf.CompareTo("Ỹ") == 0 ||
                    buf.CompareTo("Y") == 0 ||
                    buf.CompareTo("É") == 0 ||
                    buf.CompareTo("È") == 0 ||
                    buf.CompareTo("Ẻ") == 0 ||
                    buf.CompareTo("E") == 0 ||
                    buf.CompareTo("Ẽ") == 0 ||
                    buf.CompareTo("Ế") == 0 ||
                    buf.CompareTo("Ề") == 0 ||
                    buf.CompareTo("Ể") == 0 ||
                    buf.CompareTo("Ễ") == 0 ||
                    buf.CompareTo("Ê") == 0 ||
                    buf.CompareTo("ứ") == 0 ||
                    buf.CompareTo("ừ") == 0 ||
                    buf.CompareTo("ử") == 0 ||
                    buf.CompareTo("ữ") == 0 ||
                    buf.CompareTo("Ứ") == 0 ||
                    buf.CompareTo("Ừ") == 0 ||
                    buf.CompareTo("Ử") == 0 ||
                    buf.CompareTo("Ữ") == 0 ||
                    buf.CompareTo("ư") == 0 ||
                    buf.CompareTo("Ư") == 0 ||
                    buf.CompareTo("ú") == 0 ||
                    buf.CompareTo("Ú") == 0 ||
                    buf.CompareTo("ù") == 0 ||
                    buf.CompareTo("Ù") == 0 ||
                    buf.CompareTo("a") == 0 ||
                    buf.CompareTo("A") == 0 ||
                    buf.CompareTo("b") == 0 ||
                    buf.CompareTo("B") == 0 ||
                    buf.CompareTo("c") == 0 ||
                    buf.CompareTo("C") == 0 ||
                    buf.CompareTo("d") == 0 ||
                    buf.CompareTo("D") == 0 ||
                    buf.CompareTo("đ") == 0 ||
                    buf.CompareTo("Đ") == 0 ||
                    buf.CompareTo("e") == 0 ||
                    buf.CompareTo("E") == 0 ||
                    buf.CompareTo("f") == 0 ||
                    buf.CompareTo("F") == 0 ||
                    buf.CompareTo("g") == 0 ||
                    buf.CompareTo("G") == 0 ||
                    buf.CompareTo("h") == 0 ||
                    buf.CompareTo("h") == 0 ||
                    buf.CompareTo("H") == 0 ||
                    buf.CompareTo("i") == 0 ||
                    buf.CompareTo("I") == 0 ||
                    buf.CompareTo("j") == 0 ||
                    buf.CompareTo("j") == 0 ||
                    buf.CompareTo("J") == 0 ||
                    buf.CompareTo("k") == 0 ||
                    buf.CompareTo("K") == 0 ||
                    buf.CompareTo("l") == 0 ||
                    buf.CompareTo("L") == 0 ||
                    buf.CompareTo("m") == 0 ||
                    buf.CompareTo("M") == 0 ||
                    buf.CompareTo("n") == 0 ||
                    buf.CompareTo("N") == 0 ||
                    buf.CompareTo("o") == 0 ||
                    buf.CompareTo("O") == 0 ||
                    buf.CompareTo("p") == 0 ||
                    buf.CompareTo("P") == 0 ||
                    buf.CompareTo("q") == 0 ||
                    buf.CompareTo("Q") == 0 ||
                    buf.CompareTo("r") == 0 ||
                    buf.CompareTo("R") == 0 ||
                    buf.CompareTo("s") == 0 ||
                    buf.CompareTo("S") == 0 ||
                    buf.CompareTo("t") == 0 ||
                    buf.CompareTo("T") == 0 ||
                    buf.CompareTo("u") == 0 ||
                    buf.CompareTo("U") == 0 ||
                    buf.CompareTo("v") == 0 ||
                    buf.CompareTo("V") == 0 ||
                    buf.CompareTo("w") == 0 ||
                    buf.CompareTo("W") == 0 ||
                    buf.CompareTo("x") == 0 ||
                    buf.CompareTo("X") == 0 ||
                    buf.CompareTo("y") == 0 ||
                    buf.CompareTo("Y") == 0 ||
                    buf.CompareTo("z") == 0 ||
                    buf.CompareTo("Z") == 0 ||
                    buf.CompareTo("ạ") == 0 ||
                    buf.CompareTo("ậ") == 0 ||
                    buf.CompareTo("ặ") == 0 ||
                    buf.CompareTo("Ạ") == 0 ||
                    buf.CompareTo("Ậ") == 0 ||
                    buf.CompareTo("Ặ") == 0 ||
                    buf.CompareTo("ẹ") == 0 ||
                    buf.CompareTo("Ẹ") == 0 ||
                    buf.CompareTo("ệ") == 0 ||
                    buf.CompareTo("Ệ") == 0 ||
                    buf.CompareTo("ị") == 0 ||
                    buf.CompareTo("Ị") == 0 ||
                    buf.CompareTo("ọ") == 0 ||
                    buf.CompareTo("Ọ") == 0 ||
                    buf.CompareTo("ộ") == 0 ||
                    buf.CompareTo("Ộ") == 0 ||
                    buf.CompareTo("ợ") == 0 ||
                    buf.CompareTo("Ợ") == 0 ||
                    buf.CompareTo("ụ") == 0 ||
                    buf.CompareTo("Ụ") == 0 ||
                    buf.CompareTo("`") == 0 ||
                    buf.CompareTo("~") == 0 ||
                    buf.CompareTo("!") == 0 ||
                    buf.CompareTo("@") == 0 ||
                    buf.CompareTo("#") == 0 ||
                    buf.CompareTo("$") == 0 ||
                    buf.CompareTo("%") == 0 ||
                    buf.CompareTo("^") == 0 ||
                    buf.CompareTo("&") == 0 ||
                    buf.CompareTo("*") == 0 ||
                    buf.CompareTo("(") == 0 ||
                    buf.CompareTo(")") == 0 ||
                    buf.CompareTo("_") == 0 ||
                    buf.CompareTo("-") == 0 ||
                    buf.CompareTo("+") == 0 ||
                    buf.CompareTo("=") == 0 ||
                    //buf[i].CompareTo("\")==0 ||
                    buf.CompareTo("|") == 0 ||
                    buf.CompareTo(":") == 0 ||
                    buf.CompareTo(";") == 0 ||
                    buf.CompareTo("'") == 0 ||
                    //buf[i].CompareTo(""")==0 ||
                    buf.CompareTo("<") == 0 ||
                    buf.CompareTo(">") == 0 ||
                    buf.CompareTo("/") == 0 ||
                    buf.CompareTo("?") == 0 ||
                    buf.CompareTo(".") == 0 ||
                    buf.CompareTo(",") == 0 ||
                    buf.CompareTo("[") == 0 ||
                    buf.CompareTo("]") == 0 ||
                    buf.CompareTo("{") == 0 ||
                    buf.CompareTo("}") == 0 ||
                    buf.CompareTo("") == 0
                    )
                {
                    buf = "";
                    dem = dem + 1;
                }
                buf = "";
            }

            if (dem == string_input.Length)
                t = 0;

            return t;
        }

        //g chi chua 26 chu cai.
        public int _26_kt_0_9_(string string_input)
        {
            int i, dem = 0, t = 1;
            string buf = "";

            for (i = 0; i < string_input.Length; i++)
            {
                buf = buf + string_input[i];
                if (
                    buf.CompareTo("á") == 0 ||
                    buf.CompareTo("à") == 0 ||
                    buf.CompareTo("ả") == 0 ||
                    buf.CompareTo("ã") == 0 ||
                    buf.CompareTo("ấ") == 0 ||
                    buf.CompareTo("ấ") == 0 ||
                    buf.CompareTo("ấ") == 0 ||
                    buf.CompareTo("ầ") == 0 ||
                    buf.CompareTo("ẩ") == 0 ||
                    buf.CompareTo("ẫ") == 0 ||
                    buf.CompareTo("ắ") == 0 ||
                    buf.CompareTo("ằ") == 0 ||
                    buf.CompareTo("ẳ") == 0 ||
                    buf.CompareTo("ẵ") == 0 ||
                    buf.CompareTo("â") == 0 ||
                    buf.CompareTo("ă") == 0 ||
                    buf.CompareTo("a") == 0 ||
                    buf.CompareTo("ó") == 0 ||
                    buf.CompareTo("ò") == 0 ||
                    buf.CompareTo("ỏ") == 0 ||
                    buf.CompareTo("õ") == 0 ||
                    buf.CompareTo("ố") == 0 ||
                    buf.CompareTo("ồ") == 0 ||
                    buf.CompareTo("ổ") == 0 ||
                    buf.CompareTo("ỗ") == 0 ||
                    buf.CompareTo("ớ") == 0 ||
                    buf.CompareTo("ờ") == 0 ||
                    buf.CompareTo("ở") == 0 ||
                    buf.CompareTo("ỡ") == 0 ||
                    buf.CompareTo("o") == 0 ||
                    buf.CompareTo("ơ") == 0 ||
                    buf.CompareTo("ô") == 0 ||
                    buf.CompareTo("í") == 0 ||
                    buf.CompareTo("ì") == 0 ||
                    buf.CompareTo("ỉ") == 0 ||
                    buf.CompareTo("ĩ") == 0 ||
                    buf.CompareTo("ĩ") == 0 ||
                    buf.CompareTo("ĩ") == 0 ||
                    buf.CompareTo("ĩ") == 0 ||
                    buf.CompareTo("ĩ") == 0 ||
                    buf.CompareTo("i") == 0 ||
                    buf.CompareTo("ý") == 0 ||
                    buf.CompareTo("ỳ") == 0 ||
                    buf.CompareTo("ỷ") == 0 ||
                    buf.CompareTo("ỹ") == 0 ||
                    buf.CompareTo("y") == 0 ||
                    buf.CompareTo("é") == 0 ||
                    buf.CompareTo("è") == 0 ||
                    buf.CompareTo("ẻ") == 0 ||
                    buf.CompareTo("ẽ") == 0 ||
                    buf.CompareTo("ế") == 0 ||
                    buf.CompareTo("ề") == 0 ||
                    buf.CompareTo("ể") == 0 ||
                    buf.CompareTo("ễ") == 0 ||
                    buf.CompareTo("e") == 0 ||
                    buf.CompareTo("ê") == 0 ||
                    buf.CompareTo("À") == 0 ||
                    buf.CompareTo("Á") == 0 ||
                    buf.CompareTo("Ả") == 0 ||
                    buf.CompareTo("Ã") == 0 ||
                    buf.CompareTo("Ấ") == 0 ||
                    buf.CompareTo("Ầ") == 0 ||
                    buf.CompareTo("Ẩ") == 0 ||
                    buf.CompareTo("Ẫ") == 0 ||
                    buf.CompareTo("Ắ") == 0 ||
                    buf.CompareTo("Ằ") == 0 ||
                    buf.CompareTo("Ẳ") == 0 ||
                    buf.CompareTo("Ẵ") == 0 ||
                    buf.CompareTo("A") == 0 ||
                    buf.CompareTo("Â") == 0 ||
                    buf.CompareTo("Ă") == 0 ||
                    buf.CompareTo("Ó") == 0 ||
                    buf.CompareTo("Ò") == 0 ||
                    buf.CompareTo("Ỏ") == 0 ||
                    buf.CompareTo("Ỏ") == 0 ||
                    buf.CompareTo("Ỏ") == 0 ||
                    buf.CompareTo("Õ") == 0 ||
                    buf.CompareTo("Ớ") == 0 ||
                    buf.CompareTo("Ờ") == 0 ||
                    buf.CompareTo("Ở") == 0 ||
                    buf.CompareTo("Ỡ") == 0 ||
                    buf.CompareTo("Ố") == 0 ||
                    buf.CompareTo("Ồ") == 0 ||
                    buf.CompareTo("Ỗ") == 0 ||
                    buf.CompareTo("Ổ") == 0 ||
                    buf.CompareTo("Ô") == 0 ||
                    buf.CompareTo("Ơ") == 0 ||
                    buf.CompareTo("Í") == 0 ||
                    buf.CompareTo("Ì") == 0 ||
                    buf.CompareTo("Ỉ") == 0 ||
                    buf.CompareTo("Ĩ") == 0 ||
                    buf.CompareTo("I") == 0 ||
                    buf.CompareTo("Ý") == 0 ||
                    buf.CompareTo("Ỳ") == 0 ||
                    buf.CompareTo("Ỷ") == 0 ||
                    buf.CompareTo("Ỹ") == 0 ||
                    buf.CompareTo("Y") == 0 ||
                    buf.CompareTo("É") == 0 ||
                    buf.CompareTo("È") == 0 ||
                    buf.CompareTo("Ẻ") == 0 ||
                    buf.CompareTo("E") == 0 ||
                    buf.CompareTo("Ẽ") == 0 ||
                    buf.CompareTo("Ế") == 0 ||
                    buf.CompareTo("Ề") == 0 ||
                    buf.CompareTo("Ể") == 0 ||
                    buf.CompareTo("Ễ") == 0 ||
                    buf.CompareTo("Ê") == 0 ||
                    buf.CompareTo("ứ") == 0 ||
                    buf.CompareTo("ừ") == 0 ||
                    buf.CompareTo("ử") == 0 ||
                    buf.CompareTo("ữ") == 0 ||
                    buf.CompareTo("Ứ") == 0 ||
                    buf.CompareTo("Ừ") == 0 ||
                    buf.CompareTo("Ử") == 0 ||
                    buf.CompareTo("Ữ") == 0 ||
                    buf.CompareTo("ư") == 0 ||
                    buf.CompareTo("Ư") == 0 ||
                    buf.CompareTo("ú") == 0 ||
                    buf.CompareTo("Ú") == 0 ||
                    buf.CompareTo("ù") == 0 ||
                    buf.CompareTo("Ù") == 0 ||
                    buf.CompareTo("a") == 0 ||
                    buf.CompareTo("A") == 0 ||
                    buf.CompareTo("b") == 0 ||
                    buf.CompareTo("B") == 0 ||
                    buf.CompareTo("c") == 0 ||
                    buf.CompareTo("C") == 0 ||
                    buf.CompareTo("d") == 0 ||
                    buf.CompareTo("D") == 0 ||
                    buf.CompareTo("đ") == 0 ||
                    buf.CompareTo("Đ") == 0 ||
                    buf.CompareTo("e") == 0 ||
                    buf.CompareTo("E") == 0 ||
                    buf.CompareTo("f") == 0 ||
                    buf.CompareTo("F") == 0 ||
                    buf.CompareTo("g") == 0 ||
                    buf.CompareTo("G") == 0 ||
                    buf.CompareTo("h") == 0 ||
                    buf.CompareTo("h") == 0 ||
                    buf.CompareTo("H") == 0 ||
                    buf.CompareTo("i") == 0 ||
                    buf.CompareTo("I") == 0 ||
                    buf.CompareTo("j") == 0 ||
                    buf.CompareTo("j") == 0 ||
                    buf.CompareTo("J") == 0 ||
                    buf.CompareTo("k") == 0 ||
                    buf.CompareTo("K") == 0 ||
                    buf.CompareTo("l") == 0 ||
                    buf.CompareTo("L") == 0 ||
                    buf.CompareTo("m") == 0 ||
                    buf.CompareTo("M") == 0 ||
                    buf.CompareTo("n") == 0 ||
                    buf.CompareTo("N") == 0 ||
                    buf.CompareTo("o") == 0 ||
                    buf.CompareTo("O") == 0 ||
                    buf.CompareTo("p") == 0 ||
                    buf.CompareTo("P") == 0 ||
                    buf.CompareTo("q") == 0 ||
                    buf.CompareTo("Q") == 0 ||
                    buf.CompareTo("r") == 0 ||
                    buf.CompareTo("R") == 0 ||
                    buf.CompareTo("s") == 0 ||
                    buf.CompareTo("S") == 0 ||
                    buf.CompareTo("t") == 0 ||
                    buf.CompareTo("T") == 0 ||
                    buf.CompareTo("u") == 0 ||
                    buf.CompareTo("U") == 0 ||
                    buf.CompareTo("v") == 0 ||
                    buf.CompareTo("V") == 0 ||
                    buf.CompareTo("w") == 0 ||
                    buf.CompareTo("W") == 0 ||
                    buf.CompareTo("x") == 0 ||
                    buf.CompareTo("X") == 0 ||
                    buf.CompareTo("y") == 0 ||
                    buf.CompareTo("Y") == 0 ||
                    buf.CompareTo("z") == 0 ||
                    buf.CompareTo("Z") == 0 ||
                    buf.CompareTo("ạ") == 0 ||
                    buf.CompareTo("ậ") == 0 ||
                    buf.CompareTo("ặ") == 0 ||
                    buf.CompareTo("Ạ") == 0 ||
                    buf.CompareTo("Ậ") == 0 ||
                    buf.CompareTo("Ặ") == 0 ||
                    buf.CompareTo("ẹ") == 0 ||
                    buf.CompareTo("Ẹ") == 0 ||
                    buf.CompareTo("ệ") == 0 ||
                    buf.CompareTo("Ệ") == 0 ||
                    buf.CompareTo("ị") == 0 ||
                    buf.CompareTo("Ị") == 0 ||
                    buf.CompareTo("ọ") == 0 ||
                    buf.CompareTo("Ọ") == 0 ||
                    buf.CompareTo("ộ") == 0 ||
                    buf.CompareTo("Ộ") == 0 ||
                    buf.CompareTo("ợ") == 0 ||
                    buf.CompareTo("Ợ") == 0 ||
                    buf.CompareTo("ụ") == 0 ||
                    buf.CompareTo("Ụ") == 0 ||
                    buf.CompareTo("`") == 0 ||
                    buf.CompareTo("~") == 0 ||
                    buf.CompareTo("!") == 0 ||
                    buf.CompareTo("@") == 0 ||
                    buf.CompareTo("#") == 0 ||
                    buf.CompareTo("$") == 0 ||
                    buf.CompareTo("%") == 0 ||
                    buf.CompareTo("^") == 0 ||
                    buf.CompareTo("&") == 0 ||
                    buf.CompareTo("*") == 0 ||
                    buf.CompareTo("(") == 0 ||
                    buf.CompareTo(")") == 0 ||
                    buf.CompareTo("_") == 0 ||
                    buf.CompareTo("-") == 0 ||
                    buf.CompareTo("+") == 0 ||
                    buf.CompareTo("=") == 0 ||
                    //buf[i].CompareTo("\")==0 ||
                    buf.CompareTo("|") == 0 ||
                    buf.CompareTo(":") == 0 ||
                    buf.CompareTo(";") == 0 ||
                    buf.CompareTo("'") == 0 ||
                    //buf[i].CompareTo(""")==0 ||
                    buf.CompareTo("<") == 0 ||
                    buf.CompareTo(">") == 0 ||
                    buf.CompareTo("/") == 0 ||
                    buf.CompareTo("?") == 0 ||
                    buf.CompareTo(".") == 0 ||
                    buf.CompareTo(",") == 0 ||
                    buf.CompareTo("[") == 0 ||
                    buf.CompareTo("]") == 0 ||
                    buf.CompareTo("{") == 0 ||
                    buf.CompareTo("}") == 0 ||
                    buf.CompareTo(" ") == 0 ||
                    buf.CompareTo("0") == 0 ||
                    buf.CompareTo("1") == 0 ||
                    buf.CompareTo("2") == 0 ||
                    buf.CompareTo("3") == 0 ||
                    buf.CompareTo("4") == 0 ||
                    buf.CompareTo("5") == 0 ||
                    buf.CompareTo("6") == 0 ||
                    buf.CompareTo("7") == 0 ||
                    buf.CompareTo("8") == 0 ||
                    buf.CompareTo("9") == 0
                    )
                {
                    buf = "";
                    dem = dem + 1;
                }
                buf = "";
            }

            if (dem == string_input.Length)
                t = 0;

            return t;
        }

        //g chuoi khong chua khoang trang.
        //ket qua la mot chuoi khong chua 'khoang trang'.
        public string d_k_t1(string s_input)
        {
            string s_output = "";

            //Chuyen chuoi sang mang ky tu.
            char[] mang = new char[1000];
            for (int x = 0; x < s_input.Length; x++)
            {
                mang[x] = s_input[x];
            }

            //don ky tu trong chuoi.
            int i, len, j = 0;
            len = s_input.Length;

            while ((int)mang[0] == 32)
            {
                for (i = 1; i <= len; i++)
                    mang[i - 1] = mang[i];
                len = len - 1;
            }

            if (s_input.Length > 0)
            {
                while ((int)mang[len - 1] == 32)
                {
                    mang[len - 1] = '\0';
                    len = len - 1;
                    if (len < 0)
                        break;
                }
            }

            i = 0;
            while (i < len)
            {
                while ((int)mang[i] == 32)
                {
                    for (j = i + 1; j < len; j++)
                        mang[j - 1] = mang[j];
                    len = len - 1;
                }
                i = i + 1;
            }

            //Chuyen mang ky tu thanh chuoi. 
            for (int y = 0; y < len; y++)
                s_output = s_output + mang[y];

            return s_output;
        }

        //g chieu dai chuoi khong chua khoang trong.
        public int len_string(string s_input)
        {
            string s;
            s = d_k_t1(s_input);

            return s.Length;
        }

        //g xoa sanh chuoi.
        // =0 hai chuoi giong nhau, =1 hai chuoi khac nhau.
        public int sosanh_string(string s_input1, string s_input2)
        {
            int flag = 0;

            if (s_input1.Length != s_input2.Length)
                return flag = 1;
            else
                for (int i = 0; i < s_input1.Length; i++)
                    if (s_input1[i].CompareTo(s_input2[i]) != 0)
                    {
                        flag = 1;
                        break;
                    }

            return flag;
        }
    }
}
